/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mweya.individuallab2;
/**
*
* @author mweya
*/
public class Main {
private static GroceryItem[] items = new GroceryItem[4];
private static Double salesTax = new Double(15);
public void modifySalesTax(Double t) {
this.salesTax = t;
}
public static void main() {
items[0] = new GroceryItem("A Green apple that's so round it's genuinely unsettling.","AA001", "1", "1", 3.0, new Date(3,4,2019));
items[1] = new GroceryItem("A red box with a weird smell.","RB001", "1", "1", 3.0, new Date(5,6,2023));
items[2] = new GroceryItem("A single left shoe that's bent out of shape.","SH001", "1", "1", 3.0, new Date(8,7,2055));
items[3] = new GroceryItem("Bottle.","BO001", "1", "1", 3.0, new Date(1,7,2025));
int j = 0;
while (j<items.length) {
System.out.println(items[j].toString());
j = j+1;
}
}
public Double calculatePrice(GroceryItem i, int quantity) {
return (Double) i.getCost()*((100+salesTax)/100)*quantity;
}
public GroceryItem[] cheapestItems() {
GroceryItem[] toreturn = new GroceryItem[items.length];
toreturn[0] = items[0];
int j = 1;
while (j<items.length) {
int i = 0;
while (i<j) {
if (items[j].getCost() < toreturn[i].getCost()) {
GroceryItem temp = toreturn[j];
toreturn[j] = items[j];
toreturn[j+1] = temp;
}
i = i+1;
}
j = j+1;
}
return toreturn;
}
}